from pyecharts import options as opts
from pyecharts.charts import Scatter
import csv

def make_scatter():
    data=[]
    y_data = []
    with open('../csv/vilipixiv.csv','r',encoding='utf-8') as file:
        reader=csv.reader(file)
        for row in reader:
            data.append(row[0])
            y_data.append(row[3])
        data.pop(0)
        y_data.pop(0)

    hours=[time[13:15] for time in y_data]
    works=list(zip(data,hours))

    x = [d[0] for d in works]
    y_list = [int(d[1]) for d in works]
    y=[i if i!=0 else 24 for i in y_list]

    scatter=Scatter()
    scatter.add_xaxis(x)
    scatter.add_yaxis("24小时",y)
    scatter.set_global_opts(
        xaxis_opts=opts.AxisOpts(type_="category"),
        yaxis_opts=opts.AxisOpts(type_="value"),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        datazoom_opts=[opts.DataZoomOpts(range_start=0,range_end=100,orient="horizontal")]
    )

    scatter.render("../html/时间分布散点图.html")
    return scatter

if __name__ == "__main__":
    make_scatter()